home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-10-18 | 7.7 KB | 429 lines | [TEXT/CWIE] |
- // MainWindow.cp
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Lists.h>
- #include <Menus.h>
- #include <Resources.h>
- #include <Sound.h>
- #include <TextEdit.h>
- #include <ToolUtils.h>
- #include <Appearance.h>
-
- #include "Globals.h"
- #include "ResourceDefs.h"
- #include "DoScrap.h"
- #include "Miscellany.h"
- #include "Scrolling.h"
- #include "ControlUtils.h"
- #include "Add.h"
- #include "DDocData.h"
- #include "AMReminderEngine.h"
- #include "AMReminderDoc.h"
-
- #include "MainWindow.h"
-
- #include "ReminderPanel.h"
-
- //----------
- void MainWindow::Create (
- AMDoc* inDoc,
- DDocData* inData)
- {
- MainWindow* winObj = new MainWindow;
-
- if (winObj != nil) {
- winObj->Open (inDoc);
- winObj->ConnectToData (inData);
- }
- }
-
- //----------
- MainWindow::MainWindow ()
- {
- mData = nil;
- }
-
- //----------
- MainWindow::~MainWindow ()
- {
- }
-
- //----------
- AMReminderEngine* MainWindow::GetEngine ()
- {
- return (AMReminderEngine*) mDoc->mEngine;
- }
-
- //----------
- void MainWindow::Open (
- AMDoc* inDoc)
- {
- WindowPtr window;
- Handle wftb;
-
- mDoc = inDoc;
-
- window = GetNewCWindow (WIND_MainWindow, nil, (WindowPtr) -1L);
- if (mDoc->mEngine->GetFilename () [0] != 0) {
- SetWTitle (window, mDoc->mEngine->GetFilename ());
- }
- mWindow = window;
- ((AMReminderDoc*)mDoc)->mMainWindowPtr = window;
-
- SetWindowKind (window, 'AM');
- SetWRefCon (window, (long) this);
- SetPort (window);
- SetInfo (window);
-
- wftb = ::GetResource ('Wftb', WIND_MainWindow);
-
- CreateRootControl (window, &mRootControl);
-
- vScroll = nil;
- hScroll = nil;
-
-
- mLogoHandle = ::GetNewControl (CNTL_Logo, window);
- SetWindowItemFont (mLogoHandle, wftb, 1);
-
- mYearLabel = GetNewControl (CNTL_Year, window);
- SetWindowItemFont (mYearLabel, wftb, 2);
- SetControlFromTEXT (mYearLabel, TEXT_Year);
-
- mRemindersLabelLabel = GetNewControl (CNTL_RemindersLabel, window);
- SetWindowItemFont (mRemindersLabelLabel, wftb, 3);
- SetControlFromTEXT (mRemindersLabelLabel, TEXT_RemindersLabel);
-
- mRemindersHandle = ::GetNewControl (CNTL_Reminders, window);
- SetWindowItemFont (mRemindersHandle, wftb, 4);
- BuildRemindersList (mRemindersHandle);
-
- mAddHandle = ::GetNewControl (CNTL_Add, window);
- SetWindowItemFont (mAddHandle, wftb, 5);
- SetDefaultState (mAddHandle, true);
-
- mEditHandle = ::GetNewControl (CNTL_Edit, window);
- SetWindowItemFont (mEditHandle, wftb, 6);
-
- mDeleteHandle = ::GetNewControl (CNTL_Delete, window);
- SetWindowItemFont (mDeleteHandle, wftb, 7);
-
- AdvanceKeyboardFocus (window);
-
- ShowWindow (window);
- }
-
- //----------
- void MainWindow::Close ()
- {
- mData->RemoveResponder (this);
-
- ((AMReminderDoc*)mDoc)->mMainWindowPtr = nil;
- SetInfo (nil);
- HideWindow (mWindow);
- DisposeWindow (mWindow);
-
- delete this;
- }
-
- //----------
- void MainWindow::ConnectToData (
- DDocData* inData)
- {
- mData = inData;
- mData->AddResponder (this);
-
- mRemindersListBox.UseArray (mData->GetReminders ());
- SetListBoxChoice (mRemindersHandle, mData->GetReminderChoice ());
- EnableControl (mEditHandle, mData->GetIsSelected ());
- EnableControl (mDeleteHandle, mData->GetIsSelected ());
- }
-
- //----------
- void MainWindow::DataChanged (
- long inDataID)
- {
- if (inDataID == idIsSelected) {
- EnableControl (mEditHandle, mData->GetIsSelected ());
- }
- if (inDataID == idIsSelected) {
- EnableControl (mDeleteHandle, mData->GetIsSelected ());
- }
- }
-
- //----------
- void MainWindow::BuildRemindersList (
- ControlHandle inControl)
- {
- ListHandle list = GetListHandle (inControl);
-
- AMPanel* panel = ReminderPanel::Create (mWindow);
- mRemindersListBox.Initialize (list);
- mRemindersListBox.UsePanel (panel);
-
- }
-
- //----------
- void MainWindow::Control (
- ControlHandle whichControl,
- short whichPart,
- Point where)
- {
- Rect bounds;
- short newValue;
-
- ExitCurField ();
-
- if (whichControl == mRemindersHandle) {
- if (TrackClick (mRemindersHandle, where)) {
- if (WasDoubleClick (mRemindersHandle)) {
- DoEditReminder ();
- } else { // single click
- mData->SetReminderChoice (GetListBoxChoice (mRemindersHandle));
- }
- }
- }
- if (whichControl == mAddHandle) {
- if (TrackClick (mAddHandle, where)) {
- DoAddReminder ();
- }
- }
- if (whichControl == mEditHandle) {
- if (TrackClick (mEditHandle, where)) {
- DoEditReminder ();
- }
- }
- if (whichControl == mDeleteHandle) {
- if (TrackClick (mDeleteHandle, where)) {
- DoDeleteReminder ();
- }
- }
- }
-
- //----------
- void MainWindow::MouseIn (
- Point where,
- short modifiers)
- {
- Rect bounds;
-
- }
-
- //----------
- void MainWindow::ExitCurField ()
- {
- ControlHandle focus;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if (focus == nil) {
- // nothing to exit
-
- }
- }
-
- //----------
- void MainWindow::TypeIn (
- char ch)
- {
- ControlHandle focus;
- SInt16 keyCode;
-
- GetKeyboardFocus (mWindow, &focus);
-
- if ((ch == charEnter)
- || (ch == charReturn)) {
- ExitCurField ();
- SimulateClick (mAddHandle);
- DoAddReminder ();
- } else if (ch == charEsc) {
- } else if (ch == charTab) {
- DoTab ((curEvent.modifiers & optionKey) != 0);
- } else if (focus != nil) {
- keyCode = (SInt16)(curEvent.message & keyCodeMask);
- HandleControlKey (focus, keyCode, ch, (SInt16)curEvent.modifiers);
- mDoc->mEngine->SetDirty ();
- } else {
- SysBeep (1);
- }
- }
-
- //----------
- void MainWindow::Resize ()
- {
- /* application-specific code to resize items in window */
- }
-
- //----------
- void MainWindow::Scroll (
- short newValue,
- short oldValue)
- {
- /* application-specific code to scroll window */
- if (gWhichScroll == vScroll) {
- } else { // horizontal
- }
- }
-
- //----------
- void MainWindow::DoUndo ()
- {
- } // DoUndo
-
- //----------
- void MainWindow::DoCut ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECut (curTE);
- mDoc->mEngine->SetDirty ();
- scrapDirty = true;
- }
- } // DoCut
-
- //----------
- void MainWindow::DoCopy ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TECopy (curTE);
- scrapDirty = true;
- }
- } // DoCopy
-
- //----------
- void MainWindow::DoPaste ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEPaste (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoPaste
-
- //----------
- void MainWindow::DoClear ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TEDelete (curTE);
- mDoc->mEngine->SetDirty ();
- }
- } // DoClear
-
- //----------
- void MainWindow::DoSelectAll ()
- {
- TEHandle curTE = GetCurTE ();
-
- if (curTE != nil) {
- TESetSelect (0, 32767, curTE);
- }
- } // DoSelectAll
-
- //----------
- void MainWindow::DoShowClipboard ()
- {
- } // DoShowClipboard
-
- //----------
- void MainWindow::DoEditReminder ()
- {
- DReminder data;
-
- // hand-written:
- SInt32 index = mData->GetReminderChoice ();
- DReminder* oldItem = mData->GetReminders ()->GetNthItem (index);
-
- data.CopyFrom (*oldItem);
- //
-
- if (CAdd::GetAdd (&data)) {
- // hand-written:
- oldItem->CopyFrom (data);
- mData->GetReminders ()->ChangedNth (index);
- GetEngine ()->SetDirty ();
- //
- }
- }
-
- //----------
- void MainWindow::DoAddReminder ()
- {
- DReminder data;
-
- // pre-invoke code
-
- if (CAdd::GetAdd (&data)) {
- // hand-written:
- DReminder* newItem = new DReminder;
-
- newItem->CopyFrom (data);
- mData->GetReminders ()->AddItem (newItem);
- GetEngine ()->SetDirty ();
- //
- }
- }
-
- //----------
- void MainWindow::DoDeleteReminder ()
- {
- SInt32 index = mData->GetReminderChoice ();
- mData->GetReminders ()->RemoveNth (index);
- GetEngine ()->SetDirty ();
-
- }
-
- //----------
- Boolean MainWindow::DoCommand (
- long inCommand)
- {
- Boolean result = true;
-
- switch (inCommand) {
- case cmdUndo:
- DoUndo ();
- break;
- case cmdCut:
- DoCut ();
- break;
- case cmdCopy:
- DoCopy ();
- break;
- case cmdPaste:
- DoPaste ();
- break;
- case cmdClear:
- DoClear ();
- break;
- case cmdSelectAll:
- DoSelectAll ();
- break;
- case cmdShowClipboard:
- DoShowClipboard ();
- break;
- case cmdEditReminder:
- DoEditReminder ();
- break;
- case cmdAddReminder:
- DoAddReminder ();
- break;
- case cmdDeleteReminder:
- DoDeleteReminder ();
- break;
-
- default:
- result = false;
- } // switch
-
- return result;
- }
-